package com.mcptt.config.local;

import java.util.Locale;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.util.DisplayMetrics;

import com.cloudptt.api.comm.Common;
import com.cloudptt.api.product.ILanChange;
import com.cloudptt.api.product.config.call.AnswerModeConfig;
import com.cloudptt.api.product.config.call.LocalConfig;
import com.cloudptt.api.product.config.call.UserConfig;
import com.cloudptt.api.product.config.msg.MsgConfig;
import com.cloudptt.api.product.func.sys.IRestartServer;
import com.cloudptt.api.product.log.Log;
import com.cloudptt.api.product.res.Resource;
import com.mcptt.config.VideoConfig;
import com.mcptt.config.model.ImsInfo;
import com.mcptt.config.model.McIdInfo;
import com.mcptt.config.model.McpttLoginInfo;
import com.mcptt.config.model.BootStrapSvrInfo;

public class SysConfig {
    private static final String Name = "SysConfig";

    private static final String Key_Name = "name";
    private static final String Key_McId = "mcId";
    private static final String Key_Pwd = "password";

    private static final String Key_McpttId = "mcpttId";
    private static final String Key_McvideoId = "mcvideoId";
    private static final String Key_McdataId = "mcdataId";


    private static final String Key_BootStrapIp = "bootStrapIp";
    private static final String Key_BootStrapPort = "bootStrapPort";

    private static final String Key_Cms = "cms";
    private static final String Key_Gms = "gms";
    private static final String Key_Idms = "gms";
    private static final String Key_Upload = "upload";

    private static final String Key_Sbc = "sbc";
    private static final String Key_Dns = "dns";

    private static final String Key_Impi = "impi";
    private static final String Key_Impu = "impu";
    //	private static final String Key_Realm = "realm";
    private static final String Key_Domain = "domain";
    private static final String Key_Psi_Cms = "psi-cms";
    private static final String Key_Psi_Gms = "psi-gms";
    private static final String Key_Psi_McPtt = "psi-mcptt";
    private static final String Key_Psi_McVideo = "psi-mcvideo";
    private static final String Key_Psi_McData = "psi-mcdata";

    private static final String Key_AccessToken = "accessToken";
    private static final String Key_RefreshToken = "refreshToken";
    private static final String Key_ExpireData = "expireData";
    private static final String Key_ClientId = "clientId";
    private static final String Key_SaInfo = "saInfo";
    private static final String Key_UeClientId = "ueClientId";
    private static final String Key_RedirectUri = "redirectUri";
    public static final String Key_Language = "language";
    public static final String Key_GisInterval = "gisInterval";
    public static final String Key_VideoResolving = "resolving";
    public static final String Key_FileUrl = "file-url";
    public static final String Key_GroupId = "default-group-id";

    private Context ctx = null;
    private SharedPreferences sp = null;

//    private String accessToken = null;

    private String refreshToken = null;
    private long expireData = 0;
    private String clientId = null;
    private String ueClientId = null;
    private String redirectUri = null;

    private McIdInfo mcInfo = null;

    // 语言
    public static final String LAN_ZH_CN = "zh_CN";
    public static final String LAN_EN_US = "en_GB";

    public static final String Default_Domain = "crsc.mcx.mnc020.mcc460.5gr";
    public static final String Default_ClientId = "CRSC_MCX_GPH";//MCS   //SERVER DIFFERENT
    //public static final String Default_ClientId = "CRSC_MCPTT";//TEKE   //SERVER DIFFERENT
    public static final String Default_RedirectUri = "http://www.crsc.com.cn";//"http://admin";//
    public static final String Default_Sbc = "10.100.131.72:5060";
    public static final String Default_PsiCms = "cms";
    public static final String Default_PsiGms = "gms";
    public static final String Default_PsiMcPtt = "participating-mcptt";//"mcptt";
    public static final String Default_PsiMcVideo = "participating-mcvideo";//"mcvideo";
    public static final String Default_PsiMcData = "participating-mcdata";//"mcdata";


    private ImsInfo imsInfo = null;

    private BootStrapSvrInfo bootStrapSvr = null;
    private String httpProxy = null;

    private int gisInterval = 30;

    private String curLan = LAN_ZH_CN;
    private String curFuncNum = "";

    private IRestartServer server = null;
    private ILanChange lanChange = null;

    private boolean isLogined = false;
    private VideoConfig videoConfig = null;
    private boolean isDownloadGroup = false;
    private AnswerModeConfig answerModeConfig = null;
    private MsgConfig msgConfig = null;
    private UserConfig userConfig = null;

    private LocalConfig localConfig = null;

    private String fileSvrUrl = "";
    private String defaultGroupID = "";


    public SysConfig(Context ctx, IRestartServer server, ILanChange lanChange) {
        Log.debug(this.getClass(), "LocalConfig");
        this.ctx = ctx;
        this.server = server;
        this.lanChange = lanChange;
        this.isDownloadGroup = false;

        this.sp = ctx.getSharedPreferences("local", Activity.MODE_PRIVATE);

        String httpIp = sp.getString(Key_BootStrapIp, BootStrapSvrInfo.Default_Svr_Ip);
        int httpPort = sp.getInt(Key_BootStrapPort, BootStrapSvrInfo.Default_Svr_Port);
        this.bootStrapSvr = new BootStrapSvrInfo(httpIp, httpPort);

        String cms = sp.getString(Key_Cms, "");
        String gms = sp.getString(Key_Gms, "");
        String idms = sp.getString(Key_Idms, "");
        String upload = sp.getString(Key_Upload, "");
        this.bootStrapSvr.updateServerUrl(cms, gms, upload);

        String impi = sp.getString(Key_Impi, "14980024101@crsc.mcx.mnc020.mcc460.5gr");
        String impu = sp.getString(Key_Impu, "sip:14980024101@crsc.mcx.mnc020.mcc460.5gr");
        this.imsInfo = new ImsInfo(impi, impu);

        String sbc = sp.getString(Key_Sbc, Default_Sbc);
        String dns = sp.getString(Key_Sbc, "0.0.0.0");
        this.imsInfo.updateImsSbc(sbc, dns);

        String domain = sp.getString(Key_Domain, Default_Domain);
        String psiCms = sp.getString(Key_Psi_Cms, "cms");
        String psiGms = sp.getString(Key_Psi_Gms, "gms");
        String psiMcptt = sp.getString(Key_Psi_McPtt, "mcptt");
        String psiMcvideo = sp.getString(Key_Psi_McVideo, "mcvideo");
        String psiMcdata = sp.getString(Key_Psi_McData, "mcdata");
        this.imsInfo.updatePsi(domain, psiCms, psiGms, psiMcptt, psiMcvideo, psiMcdata);

        String mcId = sp.getString(Key_McId, "");
        String pwd = sp.getString(Key_Pwd, "");
        this.mcInfo = new McIdInfo(mcId, pwd);

        String name = sp.getString(Key_Name, "");
        Log.debug(this.getClass(), "LocalConfig name = " + name);
        this.mcInfo.updateName(name);
        this.defaultGroupID = sp.getString(Key_GroupId, "");


        this.clientId = sp.getString(Key_ClientId, Default_ClientId);
        if (sp.getString(Key_UeClientId, "").equals("")) {
            SharedPreferences.Editor editor = sp.edit();
//			editor.putString(Key_UeClientId, Common.getDateAndTime_s());
            editor.putString(Key_UeClientId, Common.getUUID());
            editor.commit();
        }
        this.ueClientId = sp.getString(Key_UeClientId, "");

        String mcpttId = sp.getString(Key_McpttId, "");
        String mcvideoId = sp.getString(Key_McvideoId, "");
        String mcdataId = sp.getString(Key_McdataId, "");
        String saInfo = sp.getString(Key_SaInfo, McIdInfo.Default_SaInfo);
        this.mcInfo.updateMcInfo(mcpttId, mcvideoId, mcdataId, ueClientId);
        this.mcInfo.updateSaInfo(saInfo);

        Log.debug(SysConfig.class, "LocalConfig ueClientId = " + ueClientId + " imsInfo = " + imsInfo + " mcInfo = " + mcInfo + " mcpttId = " + mcpttId + " bootStrapSvr = " + bootStrapSvr);

        this.expireData = sp.getLong(Key_ExpireData, 0);
        this.redirectUri = sp.getString(Key_RedirectUri, Default_RedirectUri);

        int videoResolving = sp.getInt(Key_VideoResolving, VideoConfig.VideoResolving_VGA);
        videoConfig = new VideoConfig(videoResolving);

        gisInterval = sp.getInt(Key_GisInterval, 30);

        String defaultLan = getDefaultLan();
        this.curLan = sp.getString(Key_Language, defaultLan);
        Locale locale = getLocale(curLan);
        Resource.init(ctx, locale);
        updateAppLanguage(locale);
        this.answerModeConfig = new AnswerModeConfig(sp);
        this.msgConfig = new MsgConfig(sp);

        this.userConfig = new UserConfig();

        Log.debug(SysConfig.class, "answerModeConfig = " + answerModeConfig);
        this.localConfig = new LocalConfig(sp);
        Log.debug(SysConfig.class, "localConfig = " + localConfig);
        this.fileSvrUrl = sp.getString(Key_FileUrl, "");
        Log.debug(SysConfig.class, "fileSvrUrl = " + fileSvrUrl);
//		if(initCallBack != null)
//		{
//			initCallBack.initialSuc(Name);
//		}
        //	this.ConfigFileVerMap = new HashMap<String, String>();
        //	String version = sp.getString(UserProfile.FileName, "");
        //	ConfigFileVerMap.put(UserProfile.FileName, version);
        //
        //	version = sp.getString(Service.FileName, "");
        //	ConfigFileVerMap.put(Service.FileName, version);
    }

    private Locale getLocale(String lanStr) {
        if (LAN_ZH_CN.equals(lanStr)) {
            return Locale.CHINA;
        } else if (LAN_EN_US.equals(lanStr)) {
            return Locale.ENGLISH;
        } else if (isZh()) {
            return Locale.CHINA;
        }
        return Locale.ENGLISH;
    }

    private void updateAppLanguage(Locale locale) {
        Resources resources = ctx.getResources();
        Configuration config = resources.getConfiguration();
        config.locale = locale;

        DisplayMetrics dm = resources.getDisplayMetrics();
        resources.updateConfiguration(config, dm);
    }

    private String getDefaultLan() {
        if (isZh()) {
            return LAN_ZH_CN;
        }
        return LAN_EN_US;
    }

    private boolean isZh() {
        Locale locale = Locale.getDefault();
        String language = locale.getLanguage();
        Log.debug(SysConfig.class, "Locale.getDefault( ) = " + language);
        if (language.startsWith("zh"))
            return true;
        else
            return false;
    }

    public void setCurLan(String curLan) {
        if (this.curLan.equals(curLan)) {
            return;
        }
        this.curLan = curLan;
        SharedPreferences.Editor editor = sp.edit();
        editor.putString(Key_Language, curLan);

        editor.commit();
        lanChange.onLanChange(curLan);
    }

    public String getCurFuncNum() {
        return curFuncNum;
    }

    public void setCurFuncNum(String curFuncNum) {
        this.curFuncNum = curFuncNum;
    }

    public void setBootStrapSvrInfo(String ip, int port) {
        Log.debug(SysConfig.class, "setBootStrapSvrInfo ip = " + ip + " port = " + port);
        this.bootStrapSvr = new BootStrapSvrInfo(ip, port);

        SharedPreferences.Editor editor = sp.edit();
        editor.putString(Key_BootStrapIp, ip);
        editor.putInt(Key_BootStrapPort, port);

        editor.commit();

//		this.server.restartServer();
    }

    public BootStrapSvrInfo getBootStrapSvr() {
        return bootStrapSvr;
    }

    public void updateBootStrapSvrUrl(String httpProxy) {
        this.httpProxy = httpProxy;
        this.bootStrapSvr.updateServerUrl(httpProxy, httpProxy, httpProxy);

        SharedPreferences.Editor editor = sp.edit();
        editor.putString(Key_Cms, httpProxy);
        editor.putString(Key_Gms, httpProxy);
//		editor.putString(Key_FileUrl, httpProxy);

        editor.commit();
    }

    public String getDefaultGroupID() {
        return defaultGroupID;
    }

    public void setDefaultGroupID(String defaultGroupID) {
        this.defaultGroupID = defaultGroupID;

        SharedPreferences.Editor editor = sp.edit();
        editor.putString(Key_GroupId, defaultGroupID);

        editor.commit();
    }

    public void setMcInfo(String mcId, String pwd) {
        Log.debug(SysConfig.class, "setMcInfo mcId = " + mcId + " pwd = " + pwd);
        this.mcInfo.updateMcIdInfo(mcId, pwd);

        SharedPreferences.Editor editor = sp.edit();
        editor.putString(Key_McId, mcId);
        editor.putString(Key_Pwd, pwd);

        editor.commit();
    }

    public void clearPwd() {
        Log.debug(SysConfig.class, "clearPwd");
        this.mcInfo.clearPwd();

        SharedPreferences.Editor editor = sp.edit();
        editor.putString(Key_Pwd, "");

        editor.commit();
    }

    public void updateImsInfo(String mcId) {
        String impi = imsInfo.toImpi(mcId);
        String impu = imsInfo.toImpu(mcId);
        Log.debug(SysConfig.class, "updateImsInfo mcId = " + mcId + " impi = " + impi + " impu = " + impu);
        this.imsInfo.updateImsInfo(impi, impu);

        SharedPreferences.Editor editor = sp.edit();
        editor.putString(Key_Impi, impi);
        editor.putString(Key_Impu, impu);

        editor.commit();
    }

    public void setMcpttLoginName(String name) {
        Log.debug(SysConfig.class, "setMcpttInfo name = " + name);
        if (mcInfo != null) {
            mcInfo.updateName(name);
        }

        SharedPreferences.Editor editor = sp.edit();
        editor.putString(Key_Name, name);

        editor.commit();
    }

    public void updateMcpttInfo(String mcpttId, String mcvideoId, String mcdataId) {
        Log.debug(SysConfig.class, "setMcpttInfo mcpttId = " + mcpttId + " mcvideoId = " + mcvideoId + " mcdataId = " + mcdataId);
        if (mcInfo != null) {
            mcInfo.updateMcInfo(mcpttId, mcvideoId, mcdataId, ueClientId);
        }

        SharedPreferences.Editor editor = sp.edit();
        editor.putString(Key_McpttId, mcpttId);
        editor.putString(Key_McvideoId, mcvideoId);
        editor.putString(Key_McdataId, mcdataId);

        editor.commit();
    }

    public void updateSaInfo(String saInfo) {
        Log.debug(SysConfig.class, "updateSaInfo saInfo = " + saInfo);
        if (mcInfo != null) {
            mcInfo.updateSaInfo(saInfo);
        }

        SharedPreferences.Editor editor = sp.edit();
        editor.putString(Key_SaInfo, saInfo);

        editor.commit();
    }


    public void updateImsSbc(String sbc, String dns) {
        Log.debug(SysConfig.class, "updateImsSbc sbc = " + sbc + " dns = " + dns);
        if (sbc != null
                && sbc.length() >= 0) {
            this.imsInfo.updateImsSbc(sbc, dns);

            SharedPreferences.Editor editor = sp.edit();
            editor.putString(Key_Sbc, sbc);
            editor.putString(Key_Dns, dns);
            editor.commit();
        }
    }

    public void updateImsPsi(String domain, String psiCms, String psiGms, String psiMcptt, String psiMcvideo, String psiMcdata) {
        Log.debug(SysConfig.class, "updateImsPsi domain = " + domain + " psiCms = " + psiCms + " psiGms = " + psiGms + " psiMcptt = " + psiMcptt + " psiMcvideo = " + psiMcvideo + " psiMcdata = " + psiMcdata);
        this.imsInfo.updatePsi(domain, psiCms, psiGms, psiMcptt, psiMcvideo, psiMcdata);

        SharedPreferences.Editor editor = sp.edit();
        editor.putString(Key_Domain, domain);
        editor.putString(Key_Psi_Cms, psiCms);
        editor.putString(Key_Psi_Gms, psiGms);
        editor.putString(Key_Psi_McPtt, psiMcptt);
        editor.putString(Key_Psi_McVideo, psiMcvideo);
        editor.putString(Key_Psi_McData, psiMcdata);

        editor.commit();
    }

    //    public boolean checkAndSaveConfigFileVer(String configFileName,String version)
    //    {
    //	if(ConfigFileVerMap == null
    //		|| ConfigFileVerMap.size() <= 0)
    //	{
    //	    return false;
    //	}
    //	String oldVesion = ConfigFileVerMap.get(configFileName);
    //	if(oldVesion != null
    //		&& oldVesion.length() <= 0
    //		&& oldVesion.equals(version))
    //	{
    //	    return true;
    //	}
    //	return false;
    //    }
    //
    //    public void SaveConfigFileVer(String configFileName,String version)
    //    {
    //	if(ConfigFileVerMap == null
    //		|| ConfigFileVerMap.size() <= 0)
    //	{
    //	    return;
    //	}
    //
    //	ConfigFileVerMap.put(configFileName, version);
    //
    //	SharedPreferences.Editor editor = sp.edit();
    //	editor.putString(configFileName, version);
    //	editor.commit();
    //    }

    public void setAccessTokenInfo(String accessToken, String refreshToken, long expireData) {
        Log.debug(SysConfig.class, "setAccessTokenInfo accessToken = " + accessToken + " refreshToken = " + refreshToken + " expireData = " + expireData);
//        this.accessToken = accessToken;
        this.refreshToken = refreshToken;
//		long time = System.currentTimeMillis();
        this.expireData = expireData;
		this.getMcpttLoginInfo().getMcIdInfo().updateAccessToken(accessToken);

        SharedPreferences.Editor editor = sp.edit();
        editor.putString(Key_AccessToken, accessToken);
        editor.putString(Key_RefreshToken, refreshToken);
        editor.putLong(Key_ExpireData, expireData);

        editor.commit();
    }

    public boolean checkMustParamOk() {
        if (imsInfo == null
                || !imsInfo.checkMustParamOk()) {
            return false;
        }
        if (clientId == null
                || clientId.length() <= 0) {
            return false;
        }
        if (redirectUri == null
                || redirectUri.length() <= 0) {
            return false;
        }
        return true;
    }

//	public boolean checkAccessTokenExpire()
//	{
//		Log.debug(this.getClass(), "checkAccessTokenExpire");
//		if(this.accessToken == null
//				|| this.accessToken.length() <= 0)
//		{
//			return true;
//		}
//		long time = System.currentTimeMillis();
//		if(time <= expireData)
//		{
//			return false;
//		}
//
//		return true;
//	}

    public void setTradeInfo(String clientId, String redirectUri) {
        Log.debug(SysConfig.class, "setImsInfo clientId = " + clientId + " redirectUri = " + redirectUri);
        this.clientId = clientId;
        this.redirectUri = redirectUri;

        if (imsInfo != null) {
            SharedPreferences.Editor editor = sp.edit();
            editor.putString(Key_ClientId, clientId);
            editor.putString(Key_RedirectUri, redirectUri);

            editor.commit();
        }
    }

    public void setUserInfoBeforLogin(String mcId, String pwd) {
        Log.debug(SysConfig.class, "setUserInfoBeforLogin num = " + mcId + " pwd = ******");
        this.isDownloadGroup = false;
        if (mcInfo != null) {
            this.setMcInfo(mcId, pwd);
            updateImsInfo(mcId);
        }
        clearAllIfOtherUser();
    }

    private void clearAllIfOtherUser() {
//		String oldNum = sp.getString(SHARED_PROP_USERNAME_OLD, "");
//		Log.d(THIS_FILE,"setUserInfoAfterLoginSuc num = " + this.userInfo.getNum() + "oldUserName = " + oldNum);
//		if(oldNum == null
//				|| oldNum.length() <= 0
//				|| !this.userInfo.isSameNum(oldNum))
//		{
//			clearDefaultGroup();
//			dbOperator.resetTables();
//			Log.d(THIS_FILE,"setUserInfoAfterLoginSuc DbUtil.resetTables");
//		}
    }

    private void clearDefaultGroup() {
//		Log.d(THIS_FILE,"clearDefaultGroup");
//		SharedPreferences.Editor editor = sp.edit();
//		editor.putString(SHARED_PROP_GRPID,"");
//
//		editor.commit();
    }

//	public void setUserInfoAfterLoginSuc(String name,String userKey, long privilege) 
//	{
//		Log.d(THIS_FILE,"setUserInfoAfterLoginSuc name = " + name + " userKey = " + userKey
//				+ " privilege = " + Long.toHexString( privilege) );
//		
//		setMcInfo()
////		name = PlugTestConfigInfo.getInstance().findUserNameByNum(name);
////		this.userInfo.setName(name);
////		this.userInfo.setUserKey(userKey);
////		this.userInfo.setPrivilege( privilege );
////
////		SharedPreferences.Editor editor = sp.edit();
////		editor.putString(SHARED_PROP_NAME, name);
////		editor.putString(SHARED_PROP_USERKEY, userKey);
////		editor.putString(SHARED_PROP_USERNAME_OLD, userInfo.getNum());
////
////		editor.commit();
//	}

    public void setUserInfoAfterLoginSuc(String name, String userKey) {
//		setMcpttLoginName(name);
//		Log.d(THIS_FILE,"setUserInfoAfterLoginSuc num = " + num);
//		this.userInfo.setNum(num);
//		this.userInfo.setUserKey(userKey);
//
//		SharedPreferences.Editor editor = sp.edit();
//		editor.putString(SHARED_PROP_NUM, num);
//		editor.putString(SHARED_PROP_USERKEY, userKey);
//
//		editor.commit();
    }

    public void setPwdAfterChgPwd(String pwd) {
//		Log.d(THIS_FILE,"setPwdAfterChgPwd pwd = " + pwd);
//		this.userInfo.setPwd(pwd);
//
//		SharedPreferences.Editor editor = sp.edit();
//		editor.putString(SHARED_PROP_PASSWORD, pwd);
//
//		editor.commit();
    }

    public void clearUserInfoAfterLogout() {
        this.isLogined = false;
        this.isDownloadGroup = false;
        this.setMcpttLoginName("");
        this.clearPwd();
        this.setAccessTokenInfo("", "", 0);
        this.updateMcpttInfo("", "", "");
//		this.setImsInfo("","",Realm_Default);
//		Log.d(THIS_FILE,"clearUserInfoAfterLogout");
//		this.userInfo.setName("");
//		this.userInfo.setUserKey("");
//		String defaultLan = getDefaultLan();
//		this.setCurLan(defaultLan);
//		Log.setDebug(false);
//		
//		dbOperator.resetTables();
//
//		SharedPreferences.Editor editor = sp.edit();
//		editor.putString(SHARED_PROP_PASSWORD, "");
//		editor.putString(SHARED_PROP_NAME, "");
//		editor.putString(SHARED_PROP_USERKEY, "");
//		editor.putString(SHARED_PROP_LANGUAGE, defaultLan);
//		//		editor.putString(Const.SHARED_PROP_GRPID,"");
//
//		editor.commit();
    }

    public void clearUserInfoAfterExit() {
        this.isDownloadGroup = false;
        this.isLogined = false;
    }

    public McIdInfo getMcInfo() {
        return mcInfo;
    }

    public McpttLoginInfo getMcpttLoginInfo() {
        return new McpttLoginInfo(bootStrapSvr, imsInfo, this.mcInfo);
    }

//    public String getAccessToken() {
//        return accessToken;
//    }

    public String getRefreshToken() {
        return refreshToken;
    }

    public long getExpireData() {
        return expireData;
    }

    public String getClientId() {
        return clientId;//"CRSC_MCX_GPH";//
    }

    public String getRedirectUri() {
        return redirectUri;
    }

    public String getCurLan() {
        return curLan;
    }

    public boolean isLogined() {
        return isLogined;
    }

    public void setLoginedTrue() {
        this.isLogined = true;
    }

    public void setGisInterval(int gisInterval) {
        this.gisInterval = gisInterval;

        SharedPreferences.Editor editor = sp.edit();
        editor.putInt(Key_GisInterval, gisInterval);

        editor.commit();
    }

    public int getGisInterval() {
        return gisInterval;
    }

    public VideoConfig getVideoConfig() {
        return videoConfig;
    }

    public void setVideoResolving(int videoResolving) {
        int val = videoConfig.getVideoResolving();
        if (val == videoResolving) {
            return;
        }
        this.videoConfig.setVideoResolving(videoResolving);

        SharedPreferences.Editor editor = sp.edit();
        editor.putInt(Key_VideoResolving, videoResolving);
        editor.commit();
    }

    public boolean isDownloadGroup() {
        return isDownloadGroup;
    }

    public void setDownloadGroupTrue() {
        this.isDownloadGroup = true;
    }

    public AnswerModeConfig getAnswerModeConfig() {
        return answerModeConfig;
    }

    public LocalConfig getLocalConfig() {
        return localConfig;
    }

    public MsgConfig getMsgConfig() {
        return msgConfig;
    }

    public UserConfig getUserConfig() {
        return userConfig;
    }

    public String getFileSvrUrl() {
        Log.debug(this.getClass(), "getFileSvrUrl fileSvrUrl = " + fileSvrUrl);
        return fileSvrUrl;
    }

    public void setFileSvrUrl(String fileSvrUrl) {
        if (httpProxy != null) {
            String newFileSvrUrl = Common.replaceHttpSvrAddr(fileSvrUrl, httpProxy);
            Log.debug(this.getClass(), "setFileSvrUrl newFileSvrUrl = " + newFileSvrUrl);
            this.fileSvrUrl = newFileSvrUrl;
        } else {
            this.fileSvrUrl = fileSvrUrl;
        }
        Log.debug(this.getClass(), "setFileSvrUrl fileSvrUrl = " + fileSvrUrl);

        SharedPreferences.Editor editor = sp.edit();
        editor.putString(Key_FileUrl, fileSvrUrl);

        editor.commit();
    }
}
